<?php

namespace App\Console\Commands;

use App\Repos\FFMpeger;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class RecordQueueWorker extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'record:queue-worker';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '视频录制的消费进程';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->info('监听消息队列 video-record...');
        $ffmpeg = new FFMpeger();
        while (true) {
            // 从队列中取出消息数据
            $ret = Redis::lpop('video-record');
            if ($ret) {
                $ret = json_decode($ret,true);
                $ret = $ffmpeg->setTargetPath($ret['path'])->recordVideo($ret['rtmp'],$ret['duration']);
                $this->info('视频录制完成，视频地址：'.$ret);
            }
        }
    }
}
